<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<link rel="stylesheet" href="../../assets/css/layui.css">
	<link rel="stylesheet" href="../../assets/css/view.css"/>
	<title></title>
</head>
<body class="layui-view-body">
<div class="layui-content">
	<div class="layui-row">
		<div class="layui-card">
			<div class="layui-card-header">添加用户</div>
			<form id="form" class="layui-form layui-card-body" >
				<div class="layui-form-item">
					<label class="layui-form-label">姓名</label>
					<div class="layui-input-block">
						<input type="text" name="username" required  lay-verify="required" placeholder="请输入用户姓名" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">电话</label>
					<div class="layui-input-block">
						<input type="text" name="userPhone" required  lay-verify="required" placeholder="请输入用户电话" autocomplete="off" class="layui-input" id="phone1">

					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">密码</label>
					<div class="layui-input-block">
						<input type="text" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<script src="../../assets/layui.all.js"></script>
<script src="/qrcode/jquery2.1.4.js"></script>
<script src="/layer/layer.js"></script>
<script>
	var form = layui.form
			,layer = layui.layer;
</script>
<script>
	var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
	$(function(){
		$("#form").submit(function(){
			var phone =$.trim($('#phone1').val());
			if (!phoneReg.test(phone)) {
				alert(" 请输入有效的手机号码");
				return false;
			}
			var windowId = layer.load();
			var username = $("input:eq(0)").val();
			var userPhone = $("input:eq(1)").val();
			var password = $("input:eq(2)").val();
			$.post("/user/insert.do",{
				username:username,
				userPhone:userPhone,
				password:password,
			},function(data){
				layer.close(windowId);
				layer.msg(data.result);
				if(data.status == 0){
					//录入成功
					$("input").val("");

				}else{
					//录入失败
				}
			});

			return false;
		});


	});
</script>
</body>
</html>